home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / rss / readhead.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.5 KB  |  74 lines

  1. /*
  2. \funcref{readheader}{BIN\_HEADER\_ $*$readheader (\params)}
  3.     {
  4.         {FILE} {*f} {binary makefile to read from}
  5.         {char} {v} {major version number of program}
  6.     }
  7.     {pointer to read header information}
  8.     {error()}
  9.     {}
  10.     {readhead.c}
  11.     {
  12.  
  13.         Function {\em readheader()} attempts to read the header in a binary
  14.         makefile and checks the major version numbers of the makefile and the
  15.         program. When the header cannot be read or when the versions do not
  16.         match, an error is issued. {\em readheader()} expects to be called
  17.         prior to any reading from the binary file: the file pointer is not
  18.         repositioned before or after the header processing.
  19.  
  20.         The return value points to a static {\em BIN\_HEADER\_} struct which is
  21.         filled with information. The fields of the return value are:
  22.  
  23.         \begin{itemize}
  24.  
  25.             \item {\em ret$\rightarrow$version} : a string of four characters
  26.             stating the version of the binary makefile. The string is {\bf not}
  27.             terminated by `$\backslash$0'.
  28.  
  29.             \item {\em ret$\rightarrow$offset[0]} : an {\em INT32} value
  30.             stating the offset of the strings area.
  31.  
  32.             \item {\em ret$\rightarrow$offset[1]} : an {\em INT32} value
  33.             stating the offset of the variables area.
  34.  
  35.             \item {\em ret$\rightarrow$offset[2]} : an {\em INT32} value
  36.             stating the offset of the filenames area.
  37.  
  38.         \end{itemize}
  39.  
  40.         The strings area is present when the offset of this area is smaller
  41.         than the offset of the variables area. The strings are represented as
  42.         {\em ascii-z} strings.
  43.  
  44.         The variables area is present when the offset of this area is smaller
  45.         than the offset of the filenames area. The variables are {\em VAR\_}
  46.         structs.
  47.  
  48.         The filenames area is always present. The filenames are represented as
  49.         `$\backslash$n'-terminated strings.
  50.  
  51.     }
  52. */
  53.  
  54. #include "icrssdef.h"
  55. #include "../icm.h"
  56.  
  57. BIN_HEADER_ *readheader (FILE *f, unsigned v)
  58. {
  59.     static BIN_HEADER_
  60.         header;
  61.  
  62.     if (! fread (&header, sizeof (BIN_HEADER_), 1, f) )
  63.         error ("cannot read header from binary file, corrupted?");
  64.     if (header.version[0] < v)
  65.         error ("The binary file was created with an older version of icmake.\n"
  66.                "Remake the binary file.");
  67.     if (header.version[0] > v)
  68.         error ("This program does not support the version which is indicated"
  69.                " by the binary\n"
  70.                "file. Upgrade to a newer program.");
  71.  
  72.     return (&header);
  73. }
  74.